package com.zzh.bc.dao.login.impl;

import com.zzh.bc.dao.login.LoginDao;
import com.zzh.bc.db.MySQLExecute;
import com.zzh.bc.db.RSUtils;
import com.zzh.bc.model.PageModel;
import com.zzh.bc.model.UserModel;

import java.sql.SQLException;
import java.util.List;

public class LoginDaoImp implements LoginDao {
    @Override
    public UserModel findObjById(String id) {
        return null;
    }

    @Override
    public  List<UserModel> findAllObjByPage(PageModel pageModel) {
        return null;
    }

    @Override
    public UserModel findUserByAccountAndPassword(String userName, String password) {
        String sql = "SELECT " + UserModel.SQL_COLUMNS + " FROM " + UserModel.TABLE_NAME + " WHERE user_name =? AND password =?";
        UserModel model = null;
        try {
             model = RSUtils.cast2Bean(MySQLExecute.executeQuery(sql, userName, password), UserModel.class);
        } catch (SQLException | IllegalAccessException | InstantiationException ex) {
            ex.printStackTrace();
        }
        return model;
    }
}
